package org.hxyjs.controller;

import org.hxyjs.dto.DTO;
import org.hxyjs.entity.AdminChef;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.AdminChefService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@Controller //@Controller注解是用spring容器生成 对象 默认对象名 adminChefController
@RequestMapping("/adminChefController") //@RequestMapping 用户请求查找该资源使用的名字 网名 默认  /adminChefController
public class AdminChefController {
	@Resource
    AdminChefService adminChefService;
	@RequestMapping("/getAllAdminChef")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<AdminChef> getAllAdminChef() throws Exception{
    	System.out.println("查询管理员");
    	return adminChefService.getAllAdminChefs();
    }
	@RequestMapping("/addAdminChef")
	@ResponseBody
	public DTO<AdminChef> addAdminChef(@RequestBody AdminChef adminChef) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加管理员成功");
		return adminChefService.addAdminChef(adminChef);
	}

	@RequestMapping("/deleteAdminChefByAcno/{acno}")
	@ResponseBody
    public DTO<AdminChef> deleteAdminChefByAcno(@PathVariable("acno") String acno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(acno+"删除管理员成功");
    	return adminChefService.deleteAdminChefByAcno(acno);
    }



	@RequestMapping("/getAdminChefByAcno/{acno}")
	@ResponseBody
	public DTO<AdminChef> getAdminChefByAcno(@PathVariable("acno") String acno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println(acno+"根据主键查询管理员成功");
		return adminChefService.getAdminChefByAcno(acno);
	}

	@RequestMapping("/updateAdminChefByAcno")
	@ResponseBody
	public DTO<AdminChef> updateAdminChefByAcno(@RequestBody AdminChef adminChef) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改管理员成功");
		System.out.println(adminChef);
		return adminChefService.updateAdminChefByAcno(adminChef);
	}

	@RequestMapping("/getAdminChefByPage")
	@ResponseBody
	public DTO<AdminChef> getAdminChefByPage(PageInfo pageInfo) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("分页查询管理员成功");
		return adminChefService.getAdminChefByPage(pageInfo);
	}

}
